package com.com.designpatterns.strategy.solution;

/**
 * Created by pankaj on 7/13/15.
 */
public class OperatorFactory {

    public static Operator operator(String operator){
        isValid(operator);
        switch (operator) {
            case "+":
                return new AdditionOperator();
            case "-":
                return new SubstractionOperator();
            case "*":
                return new MultiplicationOperator();
            case "/":
                return new DivisionOperator();
        }
        throw new IllegalArgumentException("Invalid Operator!");
    }

    public static boolean isValid(String operator){
        if (operator != "+"
                && operator != "-"
                && operator != "*"
                && operator != "/") {
            throw new IllegalArgumentException("Invalid operator: "
                    + operator
                    + ".");
        }
        return true;
    }
}
